#include #include #include #define NUM_REGION 14 int pixelRegion[NUM_REGION] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13}; #define SIGNAL_PIN 18 const char* ssid = "Abhinav"; const char* password = "jithunandu"; const char* csvHost = "raw.githubusercontent.com"; const int csvPort = 443; const char* csvURL = "/AbhinavAjith1729/Kerala-Weather-Data/main/Weather.csv"; Adafruit_NeoPixel strip(NUM_REGION, SIGNAL_PIN, NEO_GRB + NEO_KHZ800); #define RED_COL 1 #define ORANGE_COL 2 #define GREEN_COL 3 uint32_t red = strip.Color(255, 0, 0); uint32_t orange = strip.Color(255, 60, 0); uint32_t green = strip.Color(0, 255, 0); uint32_t blue = strip.Color(0, 0, 255); uint32_t white= strip.Color(255, 255, 255); uint32_t pink = strip.Color(255, 105, 80); uint32_t cyan = strip.Color(0, 255, 255); #define UPDATE_INTERVAL 10 unsigned long lastUpdateTime = 0; void setPixelColor(int region, int cases) { // array starts at 0 region = region - 1; if(cases == RED_COL) strip.setPixelColor(pixelRegion[region], red); else if(cases == ORANGE_COL) strip.setPixelColor(pixelRegion[region], orange); else if(cases == GREEN_COL) strip.setPixelColor(pixelRegion[region], green); } void updateMap() { Serial.println(); Serial.println("------------ Updating Map ------------"); WiFiClientSecure httpsClient; httpsClient.setInsecure(); if(!httpsClient.connect(csvHost, csvPort)) { Serial.println("Unable to connect to Github :("); return; } Serial.println("Connected to Github"); httpsClient.print(String("GET ") + csvURL + " HTTP/1.1\r\n" + "Host: " + csvHost + "\r\n" + "Connection: close\r\n\r\n"); // download all the headers while (httpsClient.connected()) { String line = httpsClient.readStringUntil('\n'); if (line == "\r") break; } // download first line (column headers) String line = httpsClient.readStringUntil('\n'); // download all the lines while(httpsClient.available()) { // get line and convert into char array (for strtok) String line = httpsClient.readStringUntil('\n'); char buf[line.length()]; line.toCharArray(buf, sizeof(buf)); // divide the line into tokens (comma-separated) char *p = buf; char *str; int tokenCount = 0; int regionCode; int regionNewCases; // extract region code and number of new cases while ((str = strtok_r(p, ",", &p)) != NULL) { tokenCount++; if(tokenCount == 1) regionCode = atoi(str); else if(tokenCount == 3) regionNewCases = atoi(str); } Serial.print("Region: "); Serial.print(regionCode); Serial.print(", new cases: "); Serial.println(regionNewCases); setPixelColor(regionCode, regionNewCases); } strip.show(); Serial.println("Pixel colors updated"); } void setup() { pinMode(0,INPUT_PULLUP); pinMode(17,INPUT); Serial.begin(115200); Serial.println("ItalyMap - Covid New Cases per Region"); Serial.println(); strip.begin(); strip.setBrightness(50); strip.clear(); Serial.println("NeoPixel library init DONE"); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println("WiFi init DONE"); while (WiFi.status() != WL_CONNECTED) { delay(100); } Serial.print("Connected to "); Serial.println(ssid); updateMap(); } void loop() { if(digitalRead(17)==HIGH) { if(millis() > lastUpdateTime + (UPDATE_INTERVAL * 1000)) { updateMap(); lastUpdateTime = millis(); } } if(digitalRead(17)==LOW) { for(int i = 0; i < 5; i++) strip.setPixelColor(i, green); for(int i = 5; i < 12; i++) strip.setPixelColor(i, white); for(int i = 12; i < NUM_REGION; i++) strip.setPixelColor(i, red); strip.show(); delay(900); strip.clear(); delay(500); } }